package com.yneusoft.manage.controller;

import com.yneusoft.common.model.ResponseWrapper;
import com.yneusoft.manage.model.param.CheckFatherClassificationParam;
import com.yneusoft.manage.model.param.DeleteClassificationParam;
import com.yneusoft.manage.model.param.SearchClassificationParam;
import com.yneusoft.manage.model.param.SaveClassificationParam;
import com.yneusoft.manage.service.ClassificationManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * @author lt
 * @date 2021/10/20 19:05
 * @description: 分类管理模块 接口 Controller类
 */
@RestController
public class ClassificationManageController {
    @Autowired
    private ClassificationManageService classificationManageService;

    /**
     * 1. 获取分类列表
     *
     * @param param 请求参数
     * @return null
     */
    @GetMapping("/classificationManage/getClassificationList")
    public ResponseWrapper getClassificationList(@Validated SearchClassificationParam param) {
        return classificationManageService.getClassificationList(param);
    }

    /**
     * 2.删除分类
     *
     * @param param DeleteClassificationParam
     * @return null
     */
    @PostMapping("/classificationManage/delClassification")
    public ResponseWrapper delClassification(@RequestBody @Validated DeleteClassificationParam param) {
        return classificationManageService.delClassification(param);
    }

    /**
     * 3.【新增/修改】获取分类信息
     *
     * @param aid 类型aid
     * @return null
     */
    @GetMapping("/classificationManage/getClassificationInfo")
    public ResponseWrapper getClassificationInfo(@NotNull(message = "类型aid不能为空")Integer aid) {
        return classificationManageService.getClassificationInfo(aid);
    }

    /**
     * 4.【新增/修改】获取类型列表
     *
     * @return null
     */
    @GetMapping("/classificationManage/getTypeList")
    public ResponseWrapper getTypeList() {
        return classificationManageService.getTypeList();
    }

    /**
     * 5.【新增/修改】校验父类是否为其子孙分类
     *
     * @return null
     */
    @GetMapping("/classificationManage/checkFatherClassification")
    public ResponseWrapper checkFatherClassification(@Validated CheckFatherClassificationParam param) {
        return classificationManageService.checkFatherClassification(param);
    }

    /**
     * 6.【新增/修改】保存分类
     *
     * @param param 请求参数
     * @return null
     */
    @PostMapping("/classificationManage/saveClassification")
    public ResponseWrapper saveClassification(@RequestBody @Validated SaveClassificationParam param) {
        return classificationManageService.saveClassification(param);
    }

}
